local hit_effects = require("__base__.prototypes.entity.hit-effects")

local animation = {
  layers = {
    {
      filename = "__Krastorio2Assets__/buildings/gas-power-station/gas-power-station.png",
      width = 380,
      height = 380,
      scale = 0.5,
      frame_count = 32,
      line_length = 8,
      animation_speed = 1.2,
      shift = { 0, 0 },
    },
    {
      filename = "__Krastorio2Assets__/buildings/pipe-patch/pipe-patch.png",
      width = 55,
      height = 50,
      frame_count = 1,
      repeat_count = 32,
      scale = 0.5,
      shift = { 0, 2.5 },
    },
    {
      filename = "__Krastorio2Assets__/buildings/gas-power-station/gas-power-station-sh.png",
      width = 380,
      height = 380,
      scale = 0.5,
      frame_count = 1,
      repeat_count = 32,
      animation_speed = 1.2,
      draw_as_shadow = true,
      shift = { 0, 0 },
    },
  },
}

data:extend({
  {
    type = "recipe",
    name = "kr-gas-power-station",
    energy_required = 10,
    enabled = false,
    ingredients = {
      { type = "item", name = "kr-steel-beam", amount = 10 },
      { type = "item", name = "engine-unit", amount = 20 },
      { type = "item", name = "electronic-circuit", amount = 4 },
      { type = "item", name = "pipe", amount = 4 },
    },
    results = { { type = "item", name = "kr-gas-power-station", amount = 1 } },
  },
  {
    type = "item",
    name = "kr-gas-power-station",
    icon = "__Krastorio2Assets__/icons/entities/gas-power-station.png",
    stack_size = 10,
    subgroup = "energy",
    order = "c[solar-panel]-b[gas-power-station]",
    place_result = "kr-gas-power-station",
  },
  {
    type = "generator",
    name = "kr-gas-power-station",
    icon = "__Krastorio2Assets__/icons/entities/gas-power-station.png",
    flags = { "placeable-neutral", "player-creation" },
    minable = { mining_time = 1, result = "kr-gas-power-station" },
    max_health = 750,
    heating_energy = "100kW",
    corpse = "kr-medium-random-pipes-remnants",
    dying_explosion = "medium-explosion",
    collision_box = { { -2.3, -2.3 }, { 2.3, 2.3 } },
    selection_box = { { -2.5, -2.5 }, { 2.5, 2.5 } },
    damaged_trigger_effect = hit_effects.entity(),
    resistances = {
      { type = "physical", percent = 25 },
      { type = "fire", percent = 75 },
      { type = "impact", percent = 50 },
    },
    fluid_box = {
      pipe_covers = pipecoverspictures(),
      pipe_picture = require("prototypes.buildings.pipe-picture"),
      volume = 200,
      pipe_connections = {
        { flow_direction = "input-output", direction = defines.direction.east, position = { 2, 0 } },
        { flow_direction = "input-output", direction = defines.direction.west, position = { -2, 0 } },
        { flow_direction = "input-output", direction = defines.direction.south, position = { 0, 2 } },
        { flow_direction = "input-output", direction = defines.direction.north, position = { 0, -2 } },
      },
      production_type = "input-output",
      minimum_temperature = 25.0,
    },
    fluid_usage_per_tick = 1 / 10,
    maximum_temperature = 25,
    burns_fluid = true,
    scale_fluid_usage = true,
    destroy_non_fuel_fluid = false,
    effectivity = 1,
    energy_source = {
      type = "electric",
      usage_priority = "secondary-output",
      emissions_per_minute = { pollution = 30 },
    },
    max_power_output = "4500kW",
    vehicle_impact_sound = {
      filename = "__base__/sound/car-metal-impact.ogg",
      volume = 0.65,
    },
    working_sound = {
      sound = {
        variations = {
          {
            filename = "__Krastorio2Assets__/sounds/buildings/gas-power-station-1.ogg",
            volume = 0.8,
          },
          {
            filename = "__Krastorio2Assets__/sounds/buildings/gas-power-station-2.ogg",
            volume = 0.75,
          },
        },
        aggregation = {
          max_count = 3,
          remove = false,
          count_already_playing = true,
        },
      },
      match_speed_to_activity = true,
      max_sounds_per_prototype = 3,
      fade_in_ticks = 10,
      fade_out_ticks = 30,
    },
    min_perceived_performance = 0.25,
    performance_to_sound_speedup = 0.5,
    horizontal_animation = animation,
    vertical_animation = animation,
    smoke = {
      {
        name = "kr-gas-power-station-smoke",
        north_position = util.by_pixel(47, -88),
        south_position = util.by_pixel(47, -88),
        east_position = util.by_pixel(47, -88),
        west_position = util.by_pixel(47, -88),
        frequency = 0.350,
        starting_vertical_speed = 0.05,
        slow_down_factor = 1,
        starting_frame_deviation = 60,
      },
    },
    water_reflection = {
      pictures = {
        filename = "__Krastorio2Assets__/buildings/gas-power-station/gas-power-station-reflection.png",
        priority = "extra-high",
        width = 42,
        height = 38,
        shift = util.by_pixel(0, 40),
        variation_count = 1,
        scale = 5,
      },
      rotate = false,
      orientation_to_variation = false,
    },
  },
  {
    type = "trivial-smoke",
    name = "kr-gas-power-station-smoke",
    duration = 300,
    fade_in_duration = 0,
    fade_away_duration = 180,
    spread_duration = 400,
    start_scale = 0.17,
    end_scale = 1.15,
    color = { r = 0.25, g = 0.25, b = 0.25, a = 0.75 },
    cyclic = true,
    affected_by_wind = true,
    animation = {
      width = 152,
      height = 120,
      line_length = 5,
      frame_count = 60,
      shift = { -0.53125, -0.4375 },
      priority = "high",
      animation_speed = 0.25,
      filename = "__base__/graphics/entity/smoke/smoke.png", --"__Krastorio2Assets__/buildings/gas-power-station/gas-power-station-smoke.png",
      flags = { "smoke" },
    },
  },
})
